﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;

namespace Garlic
{
    // The map class will have a list of obstacles, paths, coin position, hoop positions.
    // It's responsible for loading/cleanup of map data.

    class Map
    {
        //private Path path = new Path();
        //private Obstacle [] obstacles;
        private string name;

        public void Load(string fileName)
        {
            System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
            xd.Load(fileName);
            ParseXML(xd.DocumentElement);
        }

        public void ParseXML(XmlElement docRoot)
        {
            if (docRoot.Name != "Map")
            {
                throw new Exception("No Map tag in the passed in map XML file");
            }

            name = docRoot.GetAttribute("name");

            ParseObstacles(docRoot);
        }

        public void ParseObstacles(XmlElement obstaclesRoot)
        {
            XmlNodeList obstacleNodes = obstaclesRoot.GetElementsByTagName("Obstacle");
            //obstacles = new Obstacle[obstacleNodes.Count];
            for (int i = 0; i < obstacleNodes.Count; i++)
            {
                //obstacles[i] = new Obstacle();
                XmlElement positionElement = ((XmlElement)obstacleNodes[i])["Position"];
                float xPos = (float) Convert.ToDouble(positionElement.GetAttribute("x"));
                float yPos = (float) Convert.ToDouble(positionElement.GetAttribute("y"));
                float zPos = (float) Convert.ToDouble(positionElement.GetAttribute("z"));
                //obstacles[i].SetPosition(new Vector3(xPos, yPos, zPos));
            }
        }

        //public Path GetPath()
        //{
            //return path;
        //}

        public void Tick(GameTime gameTime)
        {
            //path.Tick(gameTime);
        }

        void CheckCollision()
        {
        }

        public Matrix GetWorldMatrix()
        {
            //return Matrix.CreateTranslation(path.GetPosition());
            return Matrix.Identity; //does nothing
        }
    }
}
